// acl下的User用户管理模块的接口
import request from '@/utils/request'
import type { UserResponseData, User, RolesData, RoleVo } from './type'
enum API {
    // 获取全部的用户账号信息
    ALLUSER_URL = '/admin/acl/user/',
    // 添加一个新的用户账号
    ADDUSER_URL = '/admin/acl/user/save',
    // 更新已有的用户账号
    UPDATEUSER_URL = '/admin/acl/user/update',
    //获取全部职位,当前账号拥有的职位接口
    ALLROLEURL = '/admin/acl/user/toAssign/',
    //给已有的用户分配角色接口
    SETROLE_URL = '/admin/acl/user/doAssignRole',
    //删除某一个账号
    DELETEUSER_URL = '/admin/acl/user/remove/',
    //批量删除的接口
    DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}
// 获取全部的用户账号信息
export const reqUserInfoAPI = (
    page: number,
    limit: number,
    username: string
) => request.get<any, UserResponseData>(
    API.ALLUSER_URL + `${page}/${limit}/?username=${username}`,
)

//添加用户与更新已有用户的接口
export const reqAddOrUpdateUserAPI = (data: User) => {
    //携带参数有ID更新
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data)
    }
}

// 获取全部的用户账号信息
export const reqallRoleAPI = (
    adminId: number
) => request.get<any, RolesData>(
    API.ALLROLEURL + `${adminId}`,
)
// 给已有的用户分配角色
export const requserRolesAPI = (data: RoleVo) => {
    return request.post<any, any>(API.SETROLE_URL, data)
}
// 删除某一个账号
export const reqRemoveUserAPI = (id: number) =>
    request.delete<any, any>(
        API.DELETEUSER_URL + `${id}`
    )

// 批量删除账号
export const reqSelectUserAPI = (data: number[]) =>
    request.delete<any, any>(
        API.SETROLE_URL, { data }
    )
